home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
webx
/
jpged26s.lzh
/
Huffman.s
< prev
next >
Wrap
Text File
|
1996-11-10
|
12KB
|
640 lines
*
*
* GETHEAD.S
*
*
*
include DOSCALL.MAC
include JPEG.MAC
include work.inc
.xref DHTDCL,DHT
.xref clear_area
.text
************************************
*
* ╩╠╧▌├░╠▐┘é╠║░─▐Éöĵô╛
*
* ôⁿù═
* a1 ╩╠╧▌├░╠▐┘▒─▐┌╜
* Åoù═
* d4.l ║░─▐Éö
* öjë≤
* d0,d6
************************************
.xdef CountCodeNumber
CountCodeNumber
moveq.l #0,d4
moveq.l #0,d0
moveq.l #16-1,d6
@@ move.b (a1)+,d0
add.w d0,d4
dbra d6,@b
lea.l -16(a1),a1
rts
***********************************************
* MAKETREE
*
* ôⁿù═
* d0.w èeDECODE_TBLé≡ïNô_é╞é╡é╜╡╠╛»─/4
* d4.w ùté╠Éö
* a0.l Tree
* a1.l Counter
* a2.l ID
* a3.l èeDECODE_TBL▒─▐┌╜
* Åoù═
* a2.l ăé╠DHT▒─▐┌╜
* öjë≤ d0-d4/d6-d7/a0-a1/a3
***********************************************
.xdef MakeTree
MakeTree
move.l d5,-(sp)
swap.w d0
move.w #$8008,d0
move.l #$ffff_ffff,(a0)+ ┤╫░ö╗ÆΦùp║░─▐
*8╦▐»─êΩôxé╔├▐║░─▐├░╠▐┘ì∞ɼ
*------------------------------
moveq.l #1,d6 î╗ì▌é╠├▐║░─▐╦▐»─Éö
moveq.l #1,d3
move.w #256,d7
Mk8bitDecodeTbl
move.l d0,-(sp)
lsr.w d7
add.w d3,d3
moveq.l #0,d5
move.b (a1)+,d5
sub.w d5,d4
*ùté╠òöò¬ì∞ɼ
*--------------------
sub.w d5,d3
bcc Mk8bitDecodeTblNextCode
add.w d5,d4
sub.w d3,d4
add.w d3,d5
moveq.l #0,d3
bra Mk8bitDecodeTblNextCode
Mk8bitDecodeTblSetCode
movem.w d6-d7,-(sp)
moveq.l #0,d0
move.b (a2)+,d0
moveq.l #$0f,d2
and.b d0,d2
lsr.b #4,d0
swap.w d0
move.b d2,d0
add.b d6,d0
cmp.b #8,d0
bls Mk8bitDecodeTblACDC
*ü@[╩╠╧▌òäìå]é╛é»é¬Ä√é▄é┴é╜ÅΩìç
*
* offset + 0.b $00
* 1.b 0é╠î┬Éö
* 2.b $00
* 3.b ò£ìå├░╠▐┘é┼ë≡É═Åoùêé╜╦▐»─Éö
* 4.w $0000([AC/DCÆl]é═Ä√é▄éτé╚é⌐é┴é╜òäìå)
* 6.w AC/DCÆlé╠╦▐»─Éö
*-----------------------------------------------
move.b d6,d0
moveq.l #0,d1
move.b d2,d1
bra Mk8bitDecodeTblNoDCAC
*ü@[╩╠╧▌òäìå]é╞[AC/DCÆl]é¬Ä√é▄é┴é╜ÅΩìç
* offset + 0.b $00
* 1.b 0é╠î┬Éö (EOBé╠ÅΩìç 64)
* 2.b $00
* 3.b ò£ìå├░╠▐┘é┼ë≡É═Åoùêé╜╦▐»─Éö
* 4.w AC/DCÆl(0ê╚ë║é╠Ælé═é│éτé╔-2é╖éΘ)
* 6.w Reserved
*-----------------------------------------------
Mk8bitDecodeTblACDC
move.l #$fffe_0000,d1
lsl.l d2,d1
tst.b d2
bnz Mk8bitDecodeTblSet
*AC/DC╦▐»─Éöé¬0é┼üA0é╠î┬Éöé¬0é╚éτé╬üAEOBé┼éáéΘ
*----------------------------
swap.w d0
tst.b d0
bnz @f 0é╠î┬Éöé¬0é┼é═é╚éó
move.w #64,d0
@@ swap.w d0
Mk8bitDecodeTblNoDCAC
move.w d7,d6
bra Mk8bitDecodeTblSet2
*├▐║░─▐├░╠▐┘Åæé½ì₧é▌
*----------------------------
Mk8bitDecodeTblSet
lsr.w d7
move.w d7,d6
subq.w #1,d2
lsr.w d2,d6
move.w d7,-(sp)
bsr Mk8bitDecodeTblSetSub
move.w (sp)+,d7
swap.w d1
neg.w d1
swap.w d1
Mk8bitDecodeTblSet2
bsr Mk8bitDecodeTblSetSub
movem.w (sp)+,d6-d7
Mk8bitDecodeTblNextCode
dbra d5,Mk8bitDecodeTblSetCode
*Ä}é╠òöò¬é╠Åêù¥
*-------------------
move.l (sp)+,d0
*ùté¬û│éóé╠é╔Ä}é¬Äcé┴é─éóéΘÅΩìçé═üA┤╫░ö╗ÆΦùp║░─▐é≡É▌ÆΦé╡ÅIù╣
*--------------------
tst.w d4
bnz Mk8bitDecodeTblùtùL ùté═é▄é╛éáéΘ
*ü@╩╠╧▌ò£ìå┤╫░
*
* offset + 0.w TreeÅπé╠ê╩Æu
* 2.b $80
* 3.b ò£ìå├░╠▐┘é┼ë≡É═Åoùêé╜╦▐»─Éö(8î┼ÆΦ)
* 4.w Reserved
* 6.w Reserved
*------------------------------------------
mulu.w d3,d7
bra 2f
1 move.l d0,(a3)+
clr.l (a3)+
lea.l 3*8(a3),a3
2 dbra.w d7,1b
bra maketreeEnd
*ùté¬Äcé┴é─éóéΘé╠é╔Ä}é¬û│é¡é╚é┴é╜éτüAÅIù╣
*--------------------
Mk8bitDecodeTblùtùL
tst.w d3
bze maketreeEnd Ä}û│é╡
*ăé╠╦▐»─┴¬»╕
*-------------------------
addq.w #1,d6
cmp.w #8,d6
bls Mk8bitDecodeTbl é▄é╛8bitò¬é╠├▐║░─▐├░╠▐┘é≡ì∞ɼé╡é─éóé╚éó
*ü@8bité≡Æ┤éªéΘ[╩╠╧▌òäìå]é╠ÅΩìç
*
* offset + 0.w TreeÅπé╠ê╩Æu
* 2.b $80
* 3.b ò£ìå├░╠▐┘é┼ë≡É═Åoùêé╜╦▐»─Éö(8î┼ÆΦ)
* 4.w Reserved
* 6.w Reserved
*-----------------------------------
*Ä}é¬ù]éτé╚éóé⌐â`âFâbâN
*------------------------
moveq.l #0,d6
move.w d3,d1
add.w d1,d1
cmp.w d4,d1
bls @f ù]éτé╚éó
move.w d3,d6
move.w d4,d3
addq.w #1,d3
lsr.w d3
sub.w d3,d6
move.l d0,d1
@@
*ù]éτé╚éóé┼éáéδéñÄ}é╠ìsé½Éµé≡É▌ÆΦé╖éΘ
*-----------------------
move.w d3,d7
swap.w d0
addq.w #1,d0
bra 2f
1 swap.w d0
move.l d0,(a3)+
clr.l (a3)+
swap.w d0
addq.w #1,d0
lea.l 3*8(a3),a3
2 dbra.w d7,1b
*ù]éΘé╠é¬èmÄ└é╚Ä}é≡ìsé½Ä~é▄éΦé╔é╖éΘ
*-----------------------
bra 2f
1 move.l d1,(a3)+
clr.l (a3)+
lea.l 3*8(a3),a3
2 dbra.w d6,1b
*8╦▐»─é≡Æ┤éªéΘ╩╠╧▌òäìåùp├░╠▐┘ì∞ɼ
*------------------------------
moveq.l #16-8-1,d6 ìléªéτéΩéΘì┼æσé╠ÄcéΦ╦▐»─Éö-1
move.w #$8000,d1 bit 15=1)ùté╠ê≤
MakeOverTree
add.w d3,d3
moveq.l #0,d5
move.b (a1)+,d5
sub.w d5,d4
*ùté╠òöò¬ì∞ɼ
*--------------------
sub.w d5,d3
bcc 2f
*Ä}é╠ÉöéµéΦùté¬æ╜éóÅΩìçüAÄ}é╠Éöé╔ìçéφé╣éΘ
*-----------------------
add.w d5,d4
sub.w d3,d4
add.w d3,d5 d5=Ä}é╠Éö (d3=d3-d5+d5)
moveq.l #0,d3
bra 2f
1 move.b (a2)+,d1
move.w d1,(a0)+
2 dbra d5,1b
*Ä}é╠òöò¬ì∞ɼ
*-------------------
*ù]éΦé╠Ä}é╠ÅΩìçé═üA┤╫░ö╗ÆΦùp║░─▐é≡ûäé▀ì₧é▐
*--------------------
move.w d3,d5
bze maketreeEnd Ä}é═û│éó
*ù]éΦé╖é¼é╠Ä}é≡èáéΘ
*-------------------
tst.w d4
bnz 2f é▄é╛ùté¬éáéΘé╠é┼ù]éΦé┼é═é╚éó
*ùté¬û│éóé╠é┼üAÄcéΦé╠Ä}é═æSòöù]éΦ
*----------------
moveq.l #-1,d0
@@ move.w d0,(a0)+
dbra d5,@b
bra maketreeEnd
1 move.w d0,(a0)+
addq.w #1,d0
2 dbra d5,1b
dbra d6,MakeOverTree
maketreeEnd
add.w d4,d4
adda.w d4,a2 ăé╠╩╠╧▌òäìå├░╠▐┘ĵô╛▒─▐┌╜îvÄZ
move.l (sp)+,d5
rts
******************
* ôⁿù═ d0.l
* d1.l
* d6.w
* d7.w
* a3.l
* Åoù═ d1.l
* öjë≤ d2.w
******************
Mk8bitDecodeTblSetSub
move.w d6,d2
subq.w #1,d2
@@ move.l d0,(a3)+
move.l d1,(a3)+
lea.l 3*8(a3),a3
dbra.w d2,@b
swap.w d1
addq.w #2,d1
swap.w d1
sub.w d6,d7
bhi Mk8bitDecodeTblSetSub
rts
******************************************
*
* ânâtâ}âôòäìåë╗âeü[âuâïì∞ɼ
*
* ôⁿù═
* é╚é╡
* Åoù═
* é╚é╡
******************************************
.xdef make_ENCODE_table
make_ENCODE_table
lea.l DHTDCL(pc),a0
lea.l DCLtable(a6),a1
bsr make_ENCODE_table_sub
lea.l ACLtable(a6),a1
bsr make_ENCODE_table_sub
lea.l DCCtable(a6),a1
bsr make_ENCODE_table_sub
lea.l ACCtable(a6),a1
make_ENCODE_table_sub
addq.l #1,a0 *é╗éΩé╝éΩé╠╩╠╧▌òäìå╦▐»─Æ╖ûêé╠ĵéΦô╛éΘÆlé╠Éö
lea.l 16(a0),a2 *é╗éΩé╝éΩé╠╩╠╧▌òäìåé╔æ╬ë₧é╖éΘÆlé╠├░╠▐┘
moveq.l #$0000,d0 *╩╠╧▌òäìå
moveq.l #$0001,d1 *╩╠╧▌òäìå╦▐»─Æ╖
move.w #$8000,d2 *╩╠╧▌òäìåë┴ÄZÆl
1:
move.b (a0)+,d3
beq 3f *é▒é╠╦▐»─Æ╖é╔é═Ælé═æ╢ì▌é╡é╚éó
2:
moveq.l #0,d4
move.b (a2)+,d4
lsl.w #2,d4
movem.w d0-d1,(a1,d4.w)
add.w d2,d0
subq.b #1,d3
bnz 2b
3:
lsr.w #1,d2
addq.w #1,d1 *╦▐»─Æ╖æ¥ë┴
cmp.w #16,d1
bls 1b
movea.l a2,a0
rts
***************************************
*
* Ælé╠Åoî╗èmùª├░╠▐┘Åëè·ë╗
*
***************************************
.xdef ClrRateTable
ClrRateTable
lea.l RateTableStart(a6),a5
move.l #RateTableEnd-RateTableStart,d5
bra clear_area
***************************************
*
* ╩╠╧▌òäìå├░╠▐┘ì┼ôKë╗
*
***************************************
.xdef OptHuffmanTable
OptHuffmanTable
moveq.l #2,d6 DHT╗▓╜▐
lea.l DHTDCL(pc),a2
moveq.l #$00,d0
moveq.l #16-4-1,d7
lea.l DCLtable(a6),a3
bsr OptHuffmanTableMake
moveq.l #$10,d0
move.w #16*16-4-1,d7
lea.l ACLtable(a6),a3
bsr OptHuffmanTableMake
tst.b colormode(a6)
bne OptHuffmanTableEnd *╙╔╕█ëµæ£é┼éáéΘ
moveq.l #$01,d0
moveq.l #16-4-1,d7
lea.l DCCtable(a6),a3
bsr OptHuffmanTableMake
moveq.l #$11,d0
move.w #16*16-4-1,d7
lea.l ACCtable(a6),a3
bsr OptHuffmanTableMake
OptHuffmanTableEnd
lea.l DHT+2(pc),a1
move.w d6,(a1)
rts
*******************************************************
*
* ╩╠╧▌┬╪░ì∞ɼ
*
*******************************************************
.xdef OptHuffmanTableMake
OptHuffmanTableMake
*╩╠╧▌┬╪░ì∞ɼ
*--------------------
move.b d0,(a2)+
addq.w #1,d6 DHT╗▓╜▐ìXÉV
lea.l HuffTree(a6),a0
moveq.l #16,d3
MakeTreeLoop
*êΩö╘û┌é╞ô±ö╘û┌é╔żé│éóÆlé╠├░╠▐┘▒─▐┌╜ĵô╛
*-----------------------
moveq.l #-1,d0 ì┼żÆl
moveq.l #-1,d1 éQö╘û┌é╔żé│éóÆl
lea.l $0000.w,a4 ì┼żÆlé╠├░╠▐┘▒─▐┌╜
movea.l a4,a5 ô±ö╘û┌é╔żé│éóÆlé╠├░╠▐┘▒─▐┌╜
*ùté╠òöò¬îƒì⌡
*---------------------
move.w d7,d4
movea.l a3,a1
bsr OptHuffmanTableSub
*Ä}é╔é╚é┴é─éóéΘòöò¬îƒì⌡
*---------------------
lea.l HuffTree(a6),a1
move.l a0,d4
sub.l a1,d4
lsr.w #3,d4
beq @f Ä}é═é▄é╛é╚éó
subq.w #1,d4
bsr OptHuffmanTableSub
@@
*Ä}é≡├░╠▐┘é╔ôoÿ^
*--------------------
*Éeé╓é╠╬▀▓▌└É▌ÆΦ
*--------------------
clr.l (a4)
move.l a0,4(a4)
*ùté╠ì┼żÆlé╠├░╠▐┘▓▌├▐»╕╜Ælé≡╩╠╧▌òäìå├░╠▐┘é╔É▌ÆΦ
*---------------------
move.l a4,d4
lea.l HuffTree(a6),a4
cmp.l a4,d4
bcs 1f ùté┼éáéΘ
cmp.l a0,d4
bcs 2f ùté┼é═é╚éó
1:
sub.l a3,d4
lsr.w #3,d4
move.b d4,(a2,d3.w)
addq.w #1,d3
2:
tst.l d1
bmi MakeTreeFormat ì¬é╔ìsé½Æàéóé╜
clr.l (a5)
move.l a0,4(a5)
*ùté╠ô±ö╘û┌é╔żé│éóÆlé╠├░╠▐┘▓▌├▐»╕╜Ælé≡╩╠╧▌òäìå├░╠▐┘é╔É▌ÆΦ
*---------------------
move.l a5,d4
cmp.l a4,d4
bcs 1f ùté┼éáéΘ
cmp.l a0,d4
bcs 2f ùté┼é═é╚éó
1:
sub.l a3,d4
lsr.w #3,d4
move.b d4,(a2,d3.w)
addq.w #1,d3
2:
*ìçîvé╠Ägùpùªé≡ôoÿ^
*-------------------
add.l d1,d0
move.l d0,(a0)
addq.l #8,a0
bra MakeTreeLoop
MakeTreeFormat
*╩╠╧▌òäìå├░╠▐┘é╔É▌ÆΦé╡é╜üA▓▌├▐»╕╜ÆlÅçé≡żé│éóÅçé⌐éτüAæσé½éóÅçé╔ò└é╤ò╧éªéΘ
*---------------------
lea.l 16(a2),a4
lea.l (a2,d3.w),a5
add.w d3,d6 DHT╗▓╜▐ìXÉV
move.l a5,-(sp) ăé╠DHT▒─▐┌╜ò█æ╢
sub.w #16-1,d3
lsr.w #1,d3
subq.w #1,d3
@@
move.b (a4),d0
move.b -(a5),(a4)+
move.b d0,(a5)
dbra d3,@b
*èeùté╠òäìå╦▐»─Æ╖é≡îvÄZé╖éΘ
*--------------------------
*èeòäìå╦▐»─Æ╖ûêé╠Ælé╠Éö╢│▌─▄░╕Åëè·ë╗
*----------------------
lea.l HuffCount(a6),a5
move.l #16*16-4,d5
bsr clear_area
*òäìå╦▐»─Æ╖îvÄZ
*---------------------
lea.l HuffCount(a6),a5
move.w d7,d4
movea.l a3,a1
1:
move.l 4(a1),d0
beq 4f ùté═æ╢ì▌é╡é╚éó
movea.l d0,a4
*ì¬é▄é┼é╜é╟éΘ
*-------------------
moveq.l #0,d1
bra 3f
2:
addq.l #1,d1
move.l 4(a4),a4
3:
cmp.l a4,a0
bne 2b é▄é╛ì¬é╢éßé╚éó
addq.b #1,-1(a5,d1.w) ╦▐»─Æ╖ûêé╠Ælé╠Éö╢│▌─
*ăé╠├░╠▐┘
*------------------
4:
addq.l #8,a1
dbra d4,1b
*òäìå╦▐»─Æ╖é≡16bité╔ɺî└é╖éΘ
*--------------------------
lea.l HuffCount+16*16-4-1(a6),a1
move.w #16*16-4-16-1,d4
1:
tst.b (a1)
beq 4f
lea.l -2(a1),a0
2:
tst.b (a0)
beq 3f
subq.b #1,(a0)
addq.b #2,1(a0)
addq.b #1,-1(a1)
subq.b #2,(a1)
bra 1b
3:
subq.l #1,a0
bra 2b
4:
subq.l #1,a1
dbra d4,1b
*╩╠╧▌òäìå├░╠▐┘é╔òäìåûêé╔èäéΦôûé─é╜Ælé≡Åæé½ì₧é▐
*--------------------------
moveq.l #16-1,d4
lea.l HuffCount(a6),a1
@@
move.b (a1)+,(a2)+
dbra.w d4,@b
movea.l (sp)+,a2 ăé╠DHT▒─▐┌╜ò£ïA
rts
******************
*
* ôⁿù═ a1 èeÆlé╠Åoî╗öΣùª├░╠▐┘
* d0 êΩö╘żé│éóÆl
* d1 ô±ö╘û┌é╔żé│éóÆl
* a4 êΩö╘żé│éóÆlé╠├░╠▐┘▒─▐┌╜
* a5 ô±ö╘û┌é╔żé│éóÆlé╠├░╠▐┘▒─▐┌╜
* d2 é▒é╠Ælê╚ë║é═üAé╖é┼é╔æ╝é╠ùté╞îïìçì╧é▌
* d4 ├░╠▐┘Éö-1
* Åoù═
* d0 êΩö╘żé│éóÆl
* d1 ô±ö╘û┌é╔żé│éóÆl
* a4 êΩö╘żé│éóÆlé╠├░╠▐┘▒─▐┌╜
* a5 ô±ö╘û┌é╔żé│éóÆlé╠├░╠▐┘▒─▐┌╜
* öjë≤ a1,d4,d5
******************
OptHuffmanTableSub
1:
move.l (a1),d5
beq 3f
cmp.l d5,d0
bcs 2f
move.l d0,d1
movea.l a4,a5
move.l d5,d0
movea.l a1,a4
bra 3f
2:
cmp.l d5,d1
bcs 3f
move.l d5,d1
movea.l a1,a5
3:
addq.l #8,a1
dbra.w d4,1b
rts
.end